package com.qdu.bean;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class year_seasonBean   implements WritableComparable<year_seasonBean> {

    private String year;
    private int  season;
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy MM");

    public year_seasonBean() {
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(year);
        dataOutput.writeInt(season);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        year=dataInput.readUTF();
        season=dataInput.readInt();
    }

    @Override
    public String toString() {
        return  year + " " + season ;
    }

    public year_seasonBean(String year, int season) {
        this.year = year;
        this.season = season;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public int getSeason() {
        return season;
    }

    public void setSeason(int season) {
        this.season = season;
    }
public void set(String  year,int  season){
        this.year=year;
        this.season=season;
}

    @Override
    public int compareTo(year_seasonBean o) {
        try {
            long thisValue = sdf.parse(this.toString()).getTime();
            long thatValue=sdf.parse(o.toString()).getTime();
            return (thisValue<thatValue?-1:(thisValue == thatValue ? 0 : 1));//若this<that为1，是倒序，若this<that 为-1,是正序
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -2;
    }
}
